Lab 2¶

Name: Aagnay Kariyal¶

Student ID: 8830232¶


BoxPlot¶

In the code block below we import some necessary libraries such as matplot lib and numpy to create a boxplot for the video game sales in the month of August.

In [ ]:
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(5, 2.7), layout='constrained')
categories = ['God of war', 'Elden Ring', 'AC: Mirage', 'MK:1', 'RDR2']
plt.title('Video Game Sales for August')
ax.bar(categories, np.random.rand(len(categories)), color=['black', 'red', 'blue', 'green', 'brown'])
Out[ ]:
<BarContainer object of 5 artists>

Displot¶


Here we use plotly to create a Displot with the help of numpy as well

In [ ]:
import plotly as px
px.offline.init_notebook_mode()
import plotly.figure_factory as ff
import numpy as np

x1 = np.random.randn(26)
x2 = np.random.randn(26) + .5
group_labels = ['2014', '2015']

colors = ['rgb(0, 0, 100)', 'rgb(0, 200, 200)']

fig = ff.create_distplot(
    [x1, x2], group_labels, bin_size=.2, colors=colors, show_rug = False)

fig.update_layout(title_text='Customized Distplot')
fig.show()

Scatter Plot¶


We use plotly and the iris dataset from Pandas to create a Scatter Plot

In [ ]:
import plotly.express as px
import plotly as pt
pt.offline.init_notebook_mode()
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color='petal_length')
fig.update_layout(title_text='Scatter Plot')
fig.show()

Linear Regression¶


We create a Linear Regression model using plotly and SciKit Learn

In [ ]:
import numpy as np
import plotly.express as px
import plotly as pt
pt.offline.init_notebook_mode()
import plotly.graph_objects as go
from sklearn.linear_model import LinearRegression

df = px.data.tips()
X = df.total_bill.values.reshape(-1, 1)

model = LinearRegression()
model.fit(X, df.tip)

x_range = np.linspace(X.min(), X.max(), 100)
y_range = model.predict(x_range.reshape(-1, 1))

fig = px.scatter(df, x='total_bill', y='tip', opacity=0.65)
fig.add_traces(go.Scatter(x=x_range, y=y_range, name='Regression Fit'))
fig.update_layout(title_text = "Linear Regression using SciKit Learn")
fig.show()

For references about the libraries click:
matplotlib
plotly